<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="jq.js"></script>
    <script>
        function login(){
            const username = $("#username").val()
            const password = $("#password").val()
            $.post("http://localhost:8080/user/login",{
                username:username,
                password:password
            },function (res){
                const user = res.data
                console.log(user)
                if(res.code == 200){
                    //把对象转为字符串
                    let jsonString = JSON.stringify(user);
                    sessionStorage.setItem('loginUser', jsonString);
                    alert('登录成功')
                    location.href = "index.html"
                }else{
                    alert("登录失败,"+res.msg)
                }
            })
        }
    </script>
</head>
<body>
    <a href="index.html">首页</a>
    <div>
        用户名:<input id="username"/>
        密码:<input id="password"/>
        <button onclick="login()">登录</button>
    </div>
</body>
</html>